const multer = require('koa-multer')

let uploadOne = (dist) => {
  let storage = multer.diskStorage({
    //文件保存路径
    destination: (req, file, cb) => {
      cb(null, 'public'+ dist)
    },
    //修改文件名称
    filename: (req, file, cb) => {
      var fileFormat = (file.originalname).split(".");  //以点分割成数组，数组的最后一项就是后缀名
      cb(null,Date.now() + "." + fileFormat[fileFormat.length - 1]);
    }
  })
  //加载配置
  let upload = multer({ storage: storage })
  return upload.single('file')
}

module.exports = {
  uploadOne,
}

